<?php
/**
 * Project: AIGC
 * Author: moufer <moufer@163.com>
 * Date: 2024/7/6 23:58
 */

namespace module\ai\library\channel\platform;

use module\ai\library\channel\abstract\Platform;
use mof\Model;

class AliyunPlatform extends Platform
{
    protected string $regUrl = 'https://bailian.console.aliyun.com/?spm=5176.29597918.J_SEsSjsNv72yRuRFS2VknO.2.35e67ca0mUwojC#/efm/model_experience_center';

    public static function getName(): string
    {
        return '通义千问';
    }

    public static function getFlag(): string
    {
        return 'aliyun';
    }

    public static function models(): array
    {
        return [
            'qwen-turbo'           => 'qwen-turbo',
            'qwen-plus'            => 'qwen-plus',
            'qwen-max'             => 'qwen-max',
            'qwen-max-longcontext' => 'qwen-max-longcontext',
            'qwen-long'            => 'qwen-long',
        ];
    }

    public function getConfigForm(Model $model = null): array
    {
        return [
            ...parent::getConfigForm($model),
            [
                "label" => "max_tokens",
                "prop"  => "config.max_tokens",
                "value" => $model['config']['max_tokens'] ?? '',
                "intro" => "最大token数。用于限制模型生成token的数量，表示生成token个数的上限。留空表示使用默认值。",
                "tip"   => "最大token数"
            ],
            [
                "label" => "top_p",
                "prop"  => "config.top_p",
                "value" => $model['config']['top_p'] ?? '',
                "intro" => "概率阈值。生成时，核采样方法的概率阈值。取值范围为（0,1.0]",
                "tip"   => "取值越大，生成的随机性越高；取值越低，生成的随机性越低。"
            ],
            [
                "label" => "top_k",
                "prop"  => "config.top_k",
                "value" => $model['config']['top_k'] ?? '',
                "intro" => "采样候选集。生成时，采样候选集的大小。取值范围在[1, 100]。",
                "tip"   => "取值越大，生成的随机性越高；取值越小，生成的确定性越高。<br>" .
                    "注意：超出取值范围，表示不启用top_k策略，此时仅有top_p策略生效。"
            ],
            [
                "label" => "temperature",
                "prop"  => "config.temperature",
                "value" => $model['config']['temperature'] ?? '',
                "intro" => "多样性。用于控制随机性和多样性的程度。取值范围：(0, 2]，不建议取值为0，无意义。",
                "tip"   => "temperature值控制了生成文本时对每个候选词的概率分布进行平滑的程度。较高的<br>" .
                    "temperature值会降低概率分布的峰值，使得更多的低概率词被选择，生成结果更加多样化；<br>" .
                    "而较低的temperature值则会增强概率分布的峰值，使得高概率词更容易被选择，生成结果更加确定。"
            ],
            [
                "label" => "presence_penalty",
                "prop"  => "config.presence_penalty",
                "value" => $model['config']['presence_penalty'] ?? '',
                "intro" => "重复度。用户控制模型生成时整个序列中的重复度。取值范围 [-2.0, 2.0]。",
                "tip"   => "提高presence_penalty时可以降低模型生成的重复度。"
            ],
        ];
    }

    public function getKeyColumns(): array
    {
        return [
            'id'      => [
                'label'      => 'ID',
                'table_hide' => true
            ],
            'api_key' => [
                'label'  => 'API-Key',
                'secret' => true,
            ]
        ];
    }


}